package com.tm.controller;


import com.tm.model.Permission;
import com.tm.service.PermissionService;
import com.tm.util.RestReturnModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @author huangp
 * @create 2021-09-12 11:24
 */
@CrossOrigin
@RestController
@RequestMapping("permission")
public class permissionController {
    @Autowired
    private PermissionService PermissionService;

    @GetMapping
    public RestReturnModel queryPermission() {
        return RestReturnModel.SUCCESS(PermissionService.queryPermission());
    }

    //新增
    @PostMapping
    public RestReturnModel addPermission(@RequestBody Permission permission){
        PermissionService.addPermission(permission);
        return RestReturnModel.SUCCESS(null);
    }
    //根据Id查询
    @GetMapping("{id}")
    public RestReturnModel queryPermissionById(@PathVariable Integer id) {

        return RestReturnModel.SUCCESS(PermissionService.queryPermissionById(id));
    }
    @ApiOperation(value = "导出")
    @GetMapping("exportFile")
    public void exportFile(HttpServletResponse response ){
        PermissionService.exportFile(response);
    }
    @ApiOperation(value = "导入")
    @PostMapping ("uploadFile")
    public void uploadFile(MultipartFile dataFile) {
        PermissionService.uploadFile(dataFile);
    }



}
